package neusoft.yuejian_11.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.AddfeedBean;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.UserModel;
import neusoft.yuejian_11.R;

//发送反馈（已改）
public class AddfeedActivity extends BaseActivity  implements RetrofitListener {
    private EditText phone;
    private TextView tv_mb_contentSize;
    private  EditText content;
    private Button add;
    private ImageButton imageButtonBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addfeed);
        initView();
        setListener();
    }


    //计数
    private void setListener() {
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        content.addTextChangedListener(new TextWatcher() {
            private CharSequence temp;
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
                // TODO Auto-generated method stub
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                // TODO Auto-generated method stub
                temp = s;
            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                int size = 150 - temp.length();
                tv_mb_contentSize.setText(size + "");
            }
        });
           add.setOnClickListener(new View.OnClickListener() {
            @Override
                public void onClick(View v) {
                String contents = content.getText().toString();
                if (contents.equals("")) {
                    Toast.makeText(AddfeedActivity.this, "请输入反馈内容", Toast.LENGTH_SHORT).show();

                } else {
                    UserModel userModel = new UserModel();
                    String phones =phone.getText().toString();
                    userModel.addfeedback(getU_id(),phones,contents,AddfeedActivity.this);
                }

                         }
                     });
    }


    private  void initView(){
        phone = (EditText) findViewById(R.id.feedphone);
        content= (EditText) findViewById(R.id.feedinfo);
        add = (Button) findViewById(R.id.addfeed);
        tv_mb_contentSize = (TextView)findViewById(R.id.tab_wmb_contentSize);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
    }


    @Override
    public void onSuccess(Object o, int flag) {
        AddfeedBean addfeedBean= (AddfeedBean) o;
        if (addfeedBean.getSuccess().equals("0")){
            Toast.makeText(AddfeedActivity.this,"发表失败",Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(AddfeedActivity.this,"发表成功",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onFail() {

    }

}
